﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace MSRoomLocator.ViewModels
{
    public class ViewPort
    {
        public double ScreenX, ScreenY, ScreenWidth, ScreenHeight;

        // check if the rectangle intersects with the screen
        public bool IntersectsWithScreen(double x1, double y1, double x2, double y2)
        {
            double minx = Math.Max(x1, ScreenX);
            double miny = Math.Max(y1, ScreenY);
            double maxx = Math.Min(x2, ScreenX + ScreenWidth);
            double maxy = Math.Min(y2, ScreenY + ScreenHeight);

            return minx < maxx && miny < maxy;
        }

        // check if a point is inside the screen view port
        public bool IsInScreen(double x, double y)
        {
            if (x < ScreenX || y < ScreenY || x > ScreenX + ScreenWidth || y > ScreenY + ScreenHeight)
            {
                return false;
            }

            return true;
        }

        public void ApplyViewport(CompositeTransform transform)
        {
            this.ScreenX = (-transform.TranslateX + transform.CenterX * (transform.ScaleX - 1)) / transform.ScaleX;
            this.ScreenY = (-transform.TranslateY + transform.CenterY * (transform.ScaleY - 1)) / transform.ScaleY;
            this.ScreenWidth = 750 / transform.ScaleX;
            this.ScreenHeight = 400 / transform.ScaleY;
        }
    }
}
